//
//  ViewController.swift
//  Cooper_BGFMDB
//
//  Created by jhfappkf@163.com on 04/28/2021.
//  Copyright (c) 2021 jhfappkf@163.com. All rights reserved.
//

import UIKit
import Cooper_BGFMDB

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        BGDB.shareManager().debug = true;
 
//        debugPrint("TestBGFMDBSqliteModel.version() ---> \(TestBGFMDBSqliteModel.version())")
//        TestBGFMDBSqliteModel.bg_update(nil, version: 2)
        
        let test = TestBGFMDBSqliteModel()
        test.gender = "男"
        test.name = "不能故步自封"
        test.id = 2
        test.one_id = 1
        
        let subModel = TestBGFMDBSqliteModel()
        subModel.name = "1111"
        
        test.model = subModel
        
        test.name = "测试修改呀"
        
        insert(model: test)

        query()
        
        TestBGFMDBSqliteModel.testMirror()
//
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    func insert(model: TestBGFMDBSqliteModel)  {
        model.bg_saveOrUpdate()
    }
    
    func query() {
        let array: [TestBGFMDBSqliteModel] = TestBGFMDBSqliteModel.bg_findAll(TestBGFMDBSqliteModel.tableName()) as! [TestBGFMDBSqliteModel]
        array.forEach { (item) in
            debugPrint("item.id ---> \(item.id) item.one_id ---> \(item.one_id) item.gender ---> \(item.gender) item.name ---> \(item.name)")
            debugPrint(item.model?.name)
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

